#include <string.h>
#include "redboolobject.h"
#include "rednullobject.h"
#include "redstringobject.h"
#include "redexceptionobject.h"

static RedObject *null_repr(RedObject *self)
{
	return RedString_FromCString("null");
}

RedTypeObject RedType_Null =
{
	RedType_INIT("null", RedNullObject, RedType_Object)

	.tp_str		= null_repr,
	.tp_repr	= null_repr,
};

RedNullObject RedNull_Null =
{
	RedObject_HEAD_INIT(RedType_Null)
};

char RedNull_IsNull(RedObject *self)
{
	if (self == Red_Null)
		return 1;

	/* objects that equals to `null` are null */
	RedObject *result = RedObject_Eq(self, Red_Null);

	/* not comparable with null, absolutely not null */
	if (!result)
	{
		RedException_Clear();
		return 0;
	}

	if (!RedBool_IsTrue(result))
	{
		Red_UNREF(result);
		return 0;
	}

	Red_UNREF(result);
	return 1;
}
